#include "Vertex.h"
#include <iostream>
#include <math.h>

using namespace std;
using namespace prog3d;




Vertex::~Vertex() {
    /*
    if (p) delete p;
    if (n) delete n;
    */
}


void Vertex::init(Soup *o) {
    /*
    p=new ;
    n=new Vector3;
    */
    _owner=o;
}

Vertex::Vertex(Soup *o) {
    init(o);
    _p.set(0,0,0);
}

unsigned Vertex::number() {
  return _number;
}

Vertex::Vertex(Soup*o,double x,double y, double z) {
    init(o);
    _p.set(x,y,z);
}

Vertex::Vertex(Soup *o,const Vector3 &p) {
    init(o);
    _p.set(p);
}


void Vertex::translate(double x,double y,double z) {
    _p.add(x,y,z);
}

void Vertex::scale(double k) {
    _p.scale(k);
}

void Vertex::scale(double kx,double ky,double kz) {
    _p.scale(kx,ky,kz);
}

void Vertex::setNumber(int i) {
    _number=i;
}

int Vertex::getNumber() {
    return _number;
}

void Vertex::averageNormalBegin() {
    _nbNormal=0;
    _n.set(0,0,0);
}

void Vertex::averageNormalEnd() {
//    cout << nbNormal << endl;
    if (fabs(_n.length2())>1e-10) {
        _n.scale(1.0/_nbNormal);
        _n.normalize();
    }
}

void Vertex::averageNormalAdd(const Vector3 &a) {
    _n.add(a);
    _nbNormal++;
}


void Vertex::set(const Vertex &v) {
	point(v.point());
	normal(v.normal());
}



